<template>
  <div id="uDetail">
    <u-head :title="tit"></u-head>
    <ul class="u_select">
      <li>
        <span>商品</span>
      </li>
      <li>
        <span>评价</span>
      </li>
      <li>
        <span>详情</span>
      </li>
      <li>
        <span>推荐</span>
      </li>
    </ul>
    <div class="details">
      <div class="img">
        <img :src="goods.img" alt="" />
      </div>
      <div class="wenzi">
        <div class="one">
          <span
            ><i>￥{{ goods.price }}</i
            ><i>￥{{ goods.market_price }}</i></span
          ><span icon="star">收藏</span>
        </div>
        <div class="two">
          <p>{{ goods.goodsname }}</p>
          <p>敏感肌可用，控油祛痘，男女可用</p>
        </div>
        <div class="three"><span>11.11限时299</span></div>
        <div class="four">
          <p>此商品与2020-11-11结束闪购特卖，品牌美妆闪购专场</p>
          <p>查看&nbsp;></p>
        </div>
        <div class="five">领取优惠券</div>
      </div>
    </div>
    <van-goods-action>
      <van-goods-action-icon icon="chat-o" text="客服" />
      <van-goods-action-icon icon="cart-o" text="购物车" />
      <van-goods-action-icon icon="shop-o" text="店铺" />
      <van-goods-action-button
        @click="goCart"
        type="warning"
        text="加入购物车"
      />
      <van-goods-action-button type="danger" text="立即购买" />
    </van-goods-action>
  </div>
</template>
<script>
import uHead from "../components/public/uHead.vue";
import http from "../utils/http";
import { mapActions, mapMutations } from "vuex";
export default {
  components: {
    uHead,
  },
  data() {
    return {
      tit: "商品详情",
      goods: "",
    };
  },
  mounted() {
    http
      .get("/api/goodsinfo", { params: { id: this.$route.query.id } })
      .then((res) => {
        res.list.img = this.$pregImg + res.list.img;
        this.goods = res.list;
        console.log(this.goods);
      });
  },
  methods: {
    ...mapActions("carts", ["addShop",'seeSure']),
    ...mapMutations("carts", ["addList"]),
    //添加商品前往购物车
    goCart() {
      this.addShop({ id: this.$route.query.id, img: this.$pregImg });
      //向后端发送数据添加商品
      http.post('/api/cartadd',{uid:JSON.parse(localStorage.getItem('user')).uid,
      goodsid:this.$route.query.id,
      num:1}).then(res=>{
        if(res.code==200){
          alert(res.msg)
        }
        this.sure==true
      })
      this.$router.push({path:'/cart',query:{id:this.$route.query.id}})
    },
  },
};
</script>
<style lang='less' scoped>
.backs {
  width: 0.2rem;
  height: 0.2rem;
  border: 0.04rem solid #fff;
  border-top: none;
  border-right: none;
  transform: rotate(45deg);
  position: fixed;
  top: 0.8rem;
  left: 0.4rem;
  font-size: 0.5rem;
  z-index: 100;
  span {
    position: absolute;
    top: -0.25rem;
    left: -0.2rem;
    display: inline-block;
    width: 30px;
    height: 30px;
  }
}

.van-goods-action {
  display: flex;
  align-items: center;
  height: 1.4rem;
}
.details {
  font-size: 0.24rem;
  width: 100%;
  overflow: hidden;
  .img {
    width: 100%;
    height: 5.5rem;
    text-align: center;
    margin-top: 0.2rem;
    img {
      width: 5.5rem;
      height: 5.5rem;
    }
  }
  .wenzi {
    padding: 0 0.3rem 0 0.3rem;
    margin-top: 0.4rem;
    .one {
      overflow: hidden;
      margin-bottom: 0.2rem;
      span:first-child {
        float: left;
        i:first-child {
          font-style: normal;
          color: red;
          font-size: 0.4rem;
          vertical-align: baseline;
        }
        i:last-child {
          margin-left: 0.2rem;
          font-style: normal;
          color: #b9b9b9;
          text-decoration: line-through;
          font-size: 0.3rem;
          vertical-align: baseline;
        }
      }
      span:last-child {
        float: right;
        color: #ff6040;
        margin-right: 0.2rem;
      }
    }
    .two {
      margin-bottom: 0.2rem;
      p:first-child {
        font-size: 0.28rem;
        font-weight: 900;
        margin-bottom: 0.1rem;
      }
      p:last-child {
        color: #b8b8b8;
      }
    }
    .three {
      margin-bottom: 0.3rem;
      span {
        display: block;
        width: 1.6rem;
        height: 0.4rem;
        line-height: 0.4rem;
        color: #fff;
        border-radius: 3px;
        text-align: center;
        background-color: #fc8067;
      }
    }
    .four {
      display: flex;
      justify-content: space-between;
      margin-bottom: 0.3rem;
      p:first-child {
        width: 4rem;
        height: 0.6rem;
        flex: 1;
      }
      p:last-child {
        width: 1rem;
        height: 0.6rem;
        text-align: right;
        color: #ff6040;
      }
    }
    .five {
      width: 1.5rem;
      background-color: #ff6040;
      height: 0.5rem;
      text-align: center;
      line-height: 0.5rem;
      border-radius: 10px;
      font-size: 0.24rem;
      color: #fff;
    }
  }
}
.u_select {
  background: red;
  width: 100%;
  height: 0.7rem;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.u_select li span {
  color: #fff;
  font-size: 0.3rem;
}
</style>